﻿#include "Goods.h"
#include<string>
#include<sstream>

using namespace std;
int Goods::getgoodsid()
{
	return goodsid;
}

string Goods::getgoodsname()
{
	return goodsname;
}

string Goods::getcatlog()
{
	return catalog;
}

int Goods::getcontain()
{
	return contain;
}

double Goods::getprice()
{
	return price;
}

int Food::getShelf_life() //获取保质期
{
	return Shelf_life;
}

std::string ElectricalAppliance::getcolor() //获取颜色
{
	return color;
}

std::istream& operator>>(std::istream& is, Goods& obj) //实现重载运算符
{
	is >> obj.price >> obj.goodsname >> obj.catalog >> obj.goodsid >> obj.contain;
	return is;
}
void Goods::ShowMe() {
	std::stringstream ss;
	ss << "goodsanme:" << goodsname << endl;
	ss << "contain:" << contain << endl;
}

//实现各子类中纯虚函数ShowMe();
void DailyGoods::ShowMe()
{
	std::stringstream ss;
	ss << "goodsanme:" << goodsname << endl;
	ss << "contain:" << contain << endl;
}

void Food::ShowMe()
{
	std::stringstream ss;
	ss << "goodsname:" << goodsname << endl;
	ss << "contain:" << contain << endl;
	ss << "Shelf_life:" << Shelf_life << "天" << endl;
}

void ElectricalAppliance::ShowMe()
{
	std::stringstream ss;
	ss << "goodsname:" << goodsname << endl;
	ss << "contain:" << contain << endl;
	ss << "color:" << color << endl;
}

Goods::Goods(double price1, string bookname1, string catalog1, int goodsid1, int contain1)
{
	price = price1;
	goodsname = bookname1;
	catalog = catalog1;
	//press = press1;
	goodsid = goodsid1;
	contain = contain1;
}
Goods::Goods() {};
std::string Goods::formatInfo() {
	std::stringstream ss;
	ss << goodsid << "\t" << goodsname << "\t\t" << catalog << "\t" << price << "\t" << contain << endl;
	return ss.str();
}
